package org.elsfs.cloud.common.mybatis.ext.sql.support.from;


import lombok.Getter;
import lombok.RequiredArgsConstructor;

/**
 * 子查询From项实现
 *

 */
@Getter
@RequiredArgsConstructor
public class SubQueryFromItem implements FromItem {

    /**
     * 子查询SQL
     */
    private final String subQuerySql;
    /**
     * 表别名
     */
    private final String tableAlias;

    /**
     * 构建SQL片段
     *
     * @return SQL片段
     */
    @Override
    public String buildSqlFragment() {
        return String.format(
            "FROM (%s) AS %s",
            this.subQuerySql,
            this.tableAlias
        );
    }
}
